tcpReadLen = 65536
udpReadLen = 65536

con_maxConn = 500
con_cachePerConn = 200*1024
server_port = 8898

serverBindIp = '0.0.0.0'
con_ssPort = 8080

import platform
platformName = platform.system()
isWindows = False
if platformName=='Windows':
    isWindows = True

con_localPort = 9996

serverIp = '154.221.19.38'
#serverIp = '192.168.100.91'
#serverIp = '192.168.1.105'
#serverIp = '155.138.216.45'
#serverIp = '127.0.0.1'
con_connBufSize = 200*1024

import struct
import platform
import socket,string,random,select
from contextlib import closing

def find_free_port(ty=socket.SOCK_DGRAM):
    with closing(socket.socket(socket.AF_INET,ty)) as s:
        s.bind(('', 0))
        s.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
        return int(s.getsockname()[1])
    
def find_free_port2(ty=socket.SOCK_DGRAM):
    s = socket.socket(socket.AF_INET,ty)
    s.bind(('', 0))
    s.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
    return int(s.getsockname()[1]),s
    
def findNPorts(n,ty=socket.SOCK_DGRAM):
    l = []
    l2 = []
    while len(l)!=n:
        i = find_free_port2(ty)
        if i[0] not in l:
            l.append(i[0])
            l2.append(i[1])            
        else:
            i[1].close()
    for one in l2:
        one.close()
    return l

def randomStringDigits(stringLength=6):
    lettersAndDigits = string.ascii_letters + string.digits
    return ''.join(random.choice(lettersAndDigits) for i in range(stringLength))

    
def dealData(st):
    msgList = []   
    pos = 0
    while True:
        if len(st)-pos<4:
            break 
        ll = struct.unpack('I',st[pos:pos+4])[0]
        if len(st)-pos<ll:
            break             
        msgList.append((st[pos+4:pos+ll]))
        pos +=ll
    return st[pos:],msgList  

class structWrapper():
    def __init__(self,s=b''):
        self.data = s
        self.pos = 0
        
    def writeArr(self,a):
        self.data += a
        self.pos += len(a)
        
    def readArr(self,l):       
        self.pos += l   
        return self.data[self.pos-l:self.pos]
    
    def writeByte(self,b):
        self.data += struct.pack('B',b)
        self.pos += 1
        
    def writeWord(self,b):
        self.data += struct.pack('H',b)
        self.pos += 2    
    def writeDWord(self,b):
        self.data += struct.pack('I',b)
        self.pos += 4       
    def writeDouble(self,b):
        self.data += struct.pack('d',b)
        self.pos += 8
        
    def writeQ(self,b):
        self.data += struct.pack('Q',b)
        self.pos += 8   
    def writeFloat(self,b):
        self.data += struct.pack('f',b)
        self.pos += 4
        
    def readFloat(self):
        r = struct.unpack('f',self.data[self.pos:self.pos+4])[0]
        self.pos += 4
        return r
            
    def readByte(self):
        r = struct.unpack('B',self.data[self.pos:self.pos+1])[0]
        self.pos += 1
        return r
    
    def readWord(self):
        r = struct.unpack('H',self.data[self.pos:self.pos+2])[0]
        self.pos += 2
        return r
    def readDWord(self):
        r = struct.unpack('I',self.data[self.pos:self.pos+4])[0]
        self.pos += 4
        return r    
    def readDouble(self):
        r = struct.unpack('d',self.data[self.pos:self.pos+8])[0]
        self.pos += 8
        return r    
    
    def readQ(self):
        r = struct.unpack('Q',self.data[self.pos:self.pos+8])[0]
        self.pos += 8
        return r        
    
    def getLeftData(self):
        return self.data[self.pos:]